<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>    
    <link rel="stylesheet" href="../../css/swiper.min.css">
    <link rel="stylesheet" href="../../font/iconfont.css">
</head>
<body>
	<!-- 收货地址 -->
	<div class="aui-content">
	    <div class="aui-list aui-media-list aui-margin-b-15">
		    <div class="aui-list-item">
	            <div class="aui-media-list-item-inner">
	                <div class="dd-info-wei">
	                     <i class="aui-iconfont aui-icon-location aui-font-size-20"></i>
	                </div>
	                <div class="aui-list-item-inner">
	                    <div class="aui-list-item-text">
	                        <div class="aui-list-item-title" id="oinfo_linkman">收货人：</div>
	                        <div class="aui-list-item-right" id="oinfo_contact"></div>
	                    </div>
	                    <div class="aui-list-item-title" id="oinfo_address">收货地址：</div>
	                </div>
	            </div>
       	    </div>
    	</div>
    </div>
    <!-- 订单详情 -->
    <div class="aui-content" style="margin-bottom:1rem;">
	    <div class="aui-list aui-media-list" id="goodslist">
		    <!--
		    <div class="aui-list-item">
			    <div class="aui-media-list-item-inner">
	                <div class="aui-list-item-media">
	                    <img src="../../image/shuoguo1.png">
	                </div>
	                <div class="aui-list-item-inner">
	                    <div class="aui-list-item-text">
	                        <div class="aui-list-item-title">水果益海</div>
	                        <div class="aui-list-item-right aui-text-warning">
                        		<div class="aui-btn aui-btn-warning aui-btn-block aui-btn-outlined aui-btn-sm anniu-ys">退货</div>
	                        </div>
	                    </div>
	                    <div class="aui-list-item-text aui-text-success">￥750.00</div>
	                    <div class="aui-list-item-text">数量：1</div>
	                </div>
	            </div>
		    </div>
		    -->
	    </div>
    </div>
    
    <!-- 订单编号时间 -->
	<div class="aui-content" style="margin-bottom:1rem;">
	    <ul class="aui-list aui-list-in">
	        <li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14" id="oinfo_order_sn">订单编号：</div>
	            </div>
	        </li>
	        <li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14" id="oinfo_create_time">下单时间：</div>
	            </div>
	        </li>
	        <li class="aui-list-item boder-none db_none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14" id="oinfo_zhuangtai">订单状态：</div>
	            </div>
	        </li>
	    </ul>
	 </div>
	
    <!-- 订单价格详情列表 -->
    <div class="aui-content" style="margin-bottom:1rem;">
	    <ul class="aui-list aui-list-in">
	    	<li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14">订单总价：</div>
	                <div class="aui-list-item-right aui-font-size-14 aui-text-success" id="oinfo_zongjia">￥750.00</div>
	            </div>
	        </li>
	        <li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14">商品总价：</div>
	                <div class="aui-list-item-right aui-font-size-14" id="oinfo_orderfee">￥750.00</div>
	            </div>
	        </li>
	        <li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14">运费：</div>
	                <div class="aui-list-item-right aui-font-size-14" id="oinfo_yunfei">￥10.00</div>
	            </div>
	        </li>
	    </ul>
	 </div>
	 
	  <!-- 订单操作记录 -->
    <div class="aui-content" style="margin-bottom:1rem;">
	    <ul class="aui-list aui-list-in" id="order_log_box">
	    <!--
	    	<li class="aui-list-item boder-none">
	            <div class="aui-list-item-inner line-h">
	                <div class="aui-list-item-title aui-font-size-14">订单总价：</div>
	                <div class="aui-list-item-right aui-font-size-14 aui-text-success" id="oinfo_zongjia">￥750.00</div>
	            </div>
	        </li>
	    -->
	    </ul>
	 </div>
	
	<!--底部-->
	<footer class="aui-bar aui-bar-tab" id="footer" style="border-top:1px #eee solid;">
		<div class="aui-info">
       		<div class="aui-info-item"></div>
            <div class="aui-info-item aui-margin-r-10" id="orderFoot">
          	    <div class="aui-btn aui-btn-warning aui-btn-block aui-btn-outlined aui-btn-sm anniu-ys">确认收货</div>
            </div>
        </div>
	</footer>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>
var db_key = 'user',myParam,db_user,useParam={};
apiready = function(){
	getuser();//获取用户信息
	myParam = api.pageParam;//获取参数
	
    useParam.rtk = RSapi.myrtk;
    useParam.mytoken = db_user.mytoken;
    useParam.oid = myParam.oid;
	
	loadinfo();//加载订单信息
	
	//监听订单状态更改记录
	api.addEventListener({
	    name: 'order_list_change'
	}, function(ret, err) {
		loadinfo();//加载订单信息
	});
}
//获取用户储存在本地的数据
function getuser() {
    db_user = $api.getStorage(db_key);
}
//加载订单信息
function loadinfo() {   
    api.ajax({
        url: RSapi.base+RSapi.OrderInfo,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: useParam },
    }, function(ret, err){
        if(err){
            //api.toast({msg: JSON.stringify(err)});
            api.alert({msg: err.msg});
        }else {
            if (ret.status>0) {                 
                //显示收货人信息
                $api.html($api.byId("oinfo_linkman"),ret.orderinfo.linkman);//收货人
                $api.html($api.byId("oinfo_contact"),ret.orderinfo.contact);//联系电话
                $api.html($api.byId("oinfo_address"),ret.orderinfo.address);//收货地址
                
                //显示购买清单
                loadGoods(ret.goodslist);                
                
                //显示金额信息
                $api.html($api.byId("oinfo_orderfee"),'￥'+ret.orderinfo.orderfee);//商品总价 
                $api.html($api.byId("oinfo_yunfei"),'￥'+ret.orderinfo.yunfei);//运费 
                $api.html($api.byId("oinfo_zongjia"),'￥'+ret.orderinfo.zongjia);//总价
                
                $api.html($api.byId("oinfo_order_sn"),'订单编号：'+ret.orderinfo.order_sn);//订单编号
				$api.html($api.byId("oinfo_zhuangtai"),'订单状态：'+ret.orderinfo.zhuangtai);//订单状态 
                $api.html($api.byId("oinfo_create_time"),'下单时间：'+ret.orderinfo.createtime);//下单时间

				//显示操作按钮
                if(ret.footbtns){
                	//清空当前显示的订单按钮
                	$api.html($api.byId('orderFoot'), '');
                	//显示新的订单按钮
                	$api.html($api.byId('orderFoot'), ret.footbtns);//显示订单操作按钮
                }else{
                	//清空当前显示的订单按钮
                	$api.html($api.byId('orderFoot'), '');
                }
                                
				loadLog(ret.orderlog);//加载订单记录
                api.parseTapmode();
            }else {
                //失败了
                api.toast({msg: ret.info});
            }
        }
    });
}
//显示订单明细
function loadGoods(list){
	var htmlstr='';
    var i;
    for (i in list) {        
    	htmlstr += '<div class="aui-list-item">';
		htmlstr += '    <div class="aui-media-list-item-inner">';
        htmlstr += '        <div class="aui-list-item-media">';
        htmlstr += '            <img src="'+list[i]['picurl']+'">';
        htmlstr += '        </div>';
        htmlstr += '        <div class="aui-list-item-inner">';
        htmlstr += '            <div class="aui-list-item-text">';
        htmlstr += '                <div class="aui-list-item-title">'+list[i]['title']+'</div>';
        htmlstr += '                <div class="aui-list-item-right aui-text-warning db_none">';
        htmlstr += '            		<div class="aui-btn aui-btn-warning aui-btn-block aui-btn-outlined aui-btn-sm anniu-ys">退货</div>';
        htmlstr += '                </div>';
        htmlstr += '            </div>';
        htmlstr += '            <div class="aui-list-item-text aui-text-success">小计：￥'+list[i]['xiaoji']+'</div>';
        htmlstr += '            <div class="aui-list-item-text">数量：'+list[i]['buy_num']+'</div>';
        htmlstr += '        </div>';
        htmlstr += '    </div>';
	    htmlstr += '</div>';
    }
    $api.html($api.byId('goodslist'),htmlstr);
}
//显示订单状态
function loadLog(list){
	var htmlstr='';
    var i;
    for (i in list) {
    	 htmlstr += '<li class="aui-list-item boder-none">';
	     htmlstr += '	<div class="aui-list-item-inner line-h">';
	     htmlstr += '   	<div class="aui-list-item-title aui-font-size-14">'+list[i].content+'</div>';
	     htmlstr += '       <div class="aui-list-item-right aui-font-size-14 aui-text-success" id="oinfo_zongjia">'+list[i].createtime+'</div>';
	     htmlstr += '   </div>';
	     htmlstr += '</li>';
    }
    $api.html($api.byId('order_log_box'),htmlstr);
}
//订单操作
function doOrder(flag) {
    if(flag == 1){
    	//取消订单操作
    	var do_order_url = RSapi.base+RSapi.OrderQuxiao;
    	var tishi_msg = '您确定要取消订单吗？';
    }else if(flag == 3){
    	//确认收货操作
    	var do_order_url = RSapi.base+RSapi.OrderShouhuo;
    	var tishi_msg = '您确定已经收到货物了吗？';
    }else{
    	api.toast({msg:'操作失败，请联系客服！'});
    }
    
    useParam.rtk = RSapi.myrtk;		
	useParam.mytoken = db_user.mytoken;
	useParam.oid = myParam.oid;
    
	//弹出操作确定框
	api.confirm({
	    title: '提醒',
	    msg: tishi_msg,
	    buttons: ['确定', '取消']
	}, function(ret, err) {
		if(ret.buttonIndex == 1){
			api.showProgress();
		    api.ajax({
		        url: do_order_url,
		        method: 'post',
		        cache: false,
		        timeout: 30,
		        dataType: 'json',
		        data: { values: useParam },
		    }, function(ret, err){ 
		        if (err) { 
		            api.toast({msg:err.msg});
		        }else{
		            api.alert({msg:ret.info});
		            //发送订单状态更改成功事件
		            api.sendEvent({
		                name: 'order_list_change',
		                extra: {}
		            });
					loadinfo();
		        }
		        api.hideProgress();
		    });	
		}	    
	});
}
//打开评论
function openPingjia(id){
	api.openWin({
        name: 'win_pingjia',
        url: '../win/pingjia_win.html',
        pageParam: {oid:myParam.oid}
    });
}
//打开支付页面
function openDopay(id){
	api.openWin({
        name: 'win_dopay',
        url: '../win/dopay_win.html',
        pageParam: {oid:myParam.oid}
    });
}
//打开退款页面
function openTuikuan(){
	alert('退款请电话联系：15737928795！');
}
</script>
</html>